<?php
switch ($_POST['lang']) {
	case 'en':
	$lg['error'] = 'Error:';
	$lg['posted'] = 'Posted';
	$lg['by'] = 'by';
	$lg['on'] = 'on';
	$lg['alldata'] = 'All the data';
	break;
	
	default:
	$lg['error'] = 'Erreur :';
	$lg['posted'] = 'Posté';
	$lg['by'] = 'par';
	$lg['on'] = 'le';
	$lg['alldata'] = 'Toutes les données';
	break;
}

if (isset($_POST['url'])) {
	require_once('../lib/simple_html_dom.php');
	require_once('../Videopian.php');
	
	try {
		$video = ($_POST['mode'] == 'oEmbed') ? Videopian::getOEmbed($_POST['url']) : Videopian::get($_POST['url']);
	} catch (Exception $e) {
	    echo '<p><strong>'.$lg['error'].'</strong> ', $e->getMessage(), '</p>';
	}
	
	if ($video) {
		
		switch ($_POST['mode']) {
			case 'oEmbed': ?><pre id="rawdata"><code class="block">
<?php echo htmlentities($video); ?>
</code></pre>
	<?php
			break;
			
			case 'normal':
			default: ?>
	<div id="player" style="float: left; margin: 10px 20px 10px 0"><img src="<?php echo $video->thumbnails[0]->url; ?>" alt="Thumbnail" width="320" /></div>
	<h3><a href="<?php echo $video->url ?>"><?php echo $video->title ?></a></h3>
	<p><?php echo nl2br($video->description) ?></p>
	<p><?php if ($video->tags) { ?><strong>Tags :</strong> <?php echo implode(', ',$video->tags) ?><br /><?php } ?>
	<strong><?php echo $lg['posted'] ?> :</strong> <?php if ($video->author_url) { ?><?php echo $lg['by'] ?> <a href="<?php echo $video->author_url ?>"><?php echo $video->author ?></a><?php } ?> <?php echo $lg['on'] ?> <?php echo date_format($video->date_published, DATE_RSS); ?></p>
	
	<p class="linkrawdata" style="display:none;"><span class="arrowshow">▼</span><span class="arrowhide">▲</span> <a href="#3" id="showrawdata"><?php echo $lg['alldata'] ?></a></p>
	<pre id="rawdata" style="clear: both"><code class="block">
<?php var_dump($video); ?>
</code></pre>

<script type="text/javascript">
//<![CDATA[
	$('#rawdata,.arrowhide').hide();
	$('#player').flash({
	    src: '<?php echo $video->player_url ?>'
	});
//]]>
</script>
<?php
		}
	}
} else {
	echo 'No URL passed to the script';
}
?>